test = 5
total = 0
def getrange(power):
	x = 1
	sum = 0
	digits = -1
	while sum > digits:
		sum = sum + 9**power
		digits = int(''.join(map(str, [9 for z in range(x)])))
		x = x + 1
	return sum

for x in range(10,getrange(test)):
	sum = 0
	numt = str(x)
	for y in range(len(numt)):
		sum = sum + int(numt[y])**test
	if sum == x:
		print(numt)
		total = total + x
		
print("Total sum: "+str(total))